package com.originskyseed.platform.cms.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.cms.mapper.CmsContentFavoriteMapper;
import com.originskyseed.platform.cms.model.CmsContentFavorite;
import com.originskyseed.platform.cms.service.ICmsContentFavoriteService;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;

/**
 * 内容正文收藏接口实现类
 *
 * @author LiangMingHui
 *
 */
@DubboService
@Component("cmsContentFavoriteService")
public class CmsContentFavoriteServiceImpl implements ICmsContentFavoriteService {

	@Resource
	private CmsContentFavoriteMapper cmsContentFavoriteMapper;

	/**
	 * deleteByPrimaryKey
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.cmsContentFavoriteMapper.deleteByPrimaryKey(id);
	}

	/**
	 * deleteByPrimaryKeys
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.cmsContentFavoriteMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * insert
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(CmsContentFavorite record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.cmsContentFavoriteMapper.insert(record);
	}

	/**
	 * insertSelective
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(CmsContentFavorite record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.cmsContentFavoriteMapper.insertSelective(record);
	}

	/**
	 * selectByPrimaryKey
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public CmsContentFavorite selectByPrimaryKey(String id) throws Exception {
		return this.cmsContentFavoriteMapper.selectByPrimaryKey(id);
	}

	/**
	 * updateByPrimaryKeySelective
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(CmsContentFavorite record) throws Exception {
		record.setUpdateTime(new Date());
		return this.cmsContentFavoriteMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * updateByPrimaryKey
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(CmsContentFavorite record) throws Exception {
		record.setUpdateTime(new Date());
		return this.cmsContentFavoriteMapper.updateByPrimaryKey(record);
	}

}
